home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * Window.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS_isModuleInitialized("IS.NOF.HTML.Window"))
- {
-
- /****h* NOF_JavaScript_Library/NOF.HTML.Window
- *
- * NAME
- * NOF.HTML.Window
- *
- * DESCRIPTION
- * External dependencies: NOF.WindowEvent, NOF.HTML.Document
- ****/
-
- /**
- * constructor
- * @param _doc
- * @param _name
- **/
- function NOF_HTML_Window( _doc, _name ) {
- this.__proto__ = NOF_HTML_Window.prototype;
-
- if (arguments.length > 0){
- this.name = _name;
- this.children = new Array();
- this.listeners = new Array();
-
- if ( _doc != null){
- if (typeof(_doc.getRawDoc) == 'function')
- this.doc = _doc;
- else
- this.doc = new NOF.HTML.Document(_doc);
- }else{
- this.doc = null;
- }
- this.document = this.doc; //this temporarily to fix all the editors
- }
- }
- {
- var member = NOF_HTML_Window.prototype;
-
- //default values for members
- member.name = null;
- member.defaultName = "GENERIC_WINDOW";
- member.visible = false;
- member.initialised = false;
- member.closed = false;
-
- //TODO: change it to app for consistency. would require updating all the editors
- member.appHnd = null; //this really should have been just app but some existing editor classes alreay make use of it for a different
- member.parent = null;
- member.children = null;
- member.listeners = null;
-
- member.doc = null;
- member.document = null; //this temporarily to fix all the editors
-
- member.defaultResource = null;
-
- member.width = null;
- member.height = null;
-
- var method = NOF_HTML_Window.prototype;
- //member accessors
- method.getDoc = function (){ return this.doc; };
- method.setDoc = function ( doc ){ this.doc = doc; };
-
- method.getName = function () {
- if (this.name != null) {
- return this.name;
- } else {
- return this.defaultName;
- }
- }
- method.setName = function ( name ){ this.name = name; }
-
- method.getApp = function (){ return this.appHnd; };
- method.setApp = function (app){ this.appHnd = app; };
-
- method.getResourceProperty = function ( key ){
- return this.getApp().getResourceProperty( key );
- };
-
- method.getParent = function (){ return this.parent; };
- method.setParent = function (parent){
- this.parent = parent;
- this.appHnd = parent.getApp();
- this.addListener( parent );
- };
-
- method.init = function (){
- this.onInit( new NOF.WindowEvent( NOF.WindowEvent.WINDOW_INITIALISED, this ) );
- };
- method.isInitialised = function (){ return this.initialised; };
- method.onInit = function ( evt ){//default onInit handler simply notifies listeners of the initialization
- if (! this.isInitialised () ){
- for (var i = 0; i < this.listeners.length; i++ ){
- try{
- this.listeners[i].windowInitialised( event );
- }catch(e){
- }
- }
- this.initialised = true;
- }
- };
- method.super_onInit = method.onInit; //merely a convenience method for subclasses to invoke it when overriding it
-
- method.close = function (){
- this.onClose( new NOF.WindowEvent( NOF.WindowEvent.WINDOW_CLOSED, this ) );
- }
-
- method.onClose = function ( event ){
- if (! this.isClosed() ){
- for (var i = 0; i < this.listeners.length; i++ ){
- try{
- this.listeners[i].windowClosed( event );
- }catch(e){
- }
- }
- this.closed = true;
- }
- }
-
- method.windowClosed = function (event) {
- if (event.getID() == NOF.WindowEvent.DIALOG_CLOSED)
- this.removeChild( event.getSource() );
- }
-
- method.super_onClose = method.onClose;//merely a convenience method for subclasses to invoke it when overriding it
- method.isClosed = function (){ return this.closed; };
-
- method.onDialogCancel = function () {}
- method.onDialogOk = function () {}
-
- method.getChildren = function (){ return this.children; };
- method.setChildren = function (children){ this.children = children; };
-
- method.getListeners = function (){ return this.listeners; };
- method.setListeners = function (listeners){ this.listeners = listeners; };
-
- method.show = function ( dlgName){
- var contentId = (dlgName != null ? dlgName : this.getName() );
-
- if ( contentId != null)
- this.document.setElementAttribute (contentId, "class", "tabshow");
- };
-
- method.hide = function ( dlgName ){
- var contentId = (dlgName != null ? dlgName : this.getName() );
-
- if ( contentId != null)
- this.document.setElementAttribute (contentId, "class", "tabhide");
- };
-
- method.getChild = function ( _name ){
- for (var i = 0; i < this.children.length; i++ )
- if ( this.children[i].getName() == _name )
- return this.children[i];
- return null;
- };
-
- method.addChild = function ( child ){
- for (var i=0; i<this.children.length; i++)
- if ( child == this.children[i] )
- return;
-
- this.children[this.children.length] = child;
- child.setParent( this );
- };
-
- method.removeChild = function ( child ){
- for (var i = 0; i < this.children.length; i++ )
- if (child == this.children[i] ){
- this.children[i] = this.children[this.children.length-1];
- this.children.length--;
- }
- };
-
- method.addListener = function ( listener ){
- for (var i=0; i<this.listeners.length; i++)
- if ( this.listeners[i] == listener )
- return;
-
- this.listeners[this.listeners.length] = listener;
- };
-
- method.removeListener = function ( listener ){
- for (var i = 0; i < this.listeners.length; i++ )
- if ( this.listeners[i] == listener ) {
- this.listeners[i] = this.listeners[this.listeners.length -1];
- this.listeners.length--;
- }
- };
-
- method.notifyListeners = function ( event ){
- for (var i = 0; i < this.listeners.length; i++ ){
- try{
- this.listeners[i].actionPerformed( event );
- }catch(e){
- this.appHnd.ERROR('exc: ' + e.message);
- }
- }
- };
-
- /** action
-
- @param evt name.
- */
- method.action = function ( evt ) {
- var action = evt.getID();
-
- var tmpStr = this.getName() + ".";
- var isQualified = false;
-
- if ( (isQualified = action.indexOf( tmpStr ) == 0) || (action.indexOf(".") == -1)) {//current window is the target
- if ( isQualified )
- action = action.substring( tmpStr.length );
-
- try {
- return eval("this.on" + action + "( evt.getSource() )");
- }catch( e ){
- //debugger;
- //this.appHnd.ERROR( "[" + this.getName() + "] " + action + " failed! " + e.name + ": " + e.message );
- //throw e;
- }
- }else{//iterate over the list of children and if one matches invoke action on it
- var target = action.substring( 0, action.indexOf(".") );
-
- //strip the window name from event.id. this way we allow propagation down to window hierarchy
- evt.setID( action.substring( target.length + 1 ) );
- for (var i=0; i < this.children.length; i++) {
- if ( target == this.children[i].getName() ) {
- return this.children[i].action( evt );
- }
- }
- }
- }
-
- /** actionPerformed
- @param evt name.
- */
- method.actionPerformed = function ( evt ) {
- //this.appHnd.TRACE( "[action performed] " + this.getName() + " - " + evt.getID() + " - " + evt.getSource());
- return this.action(evt);
- }
-
- method.toString = function () {
- return this.getName() + "{ Parent:" + this.parent + ";ChildrenNr:" + this.children.length + ";Listeners:" + this.listeners.length + "}";
- }
-
- method.setTitle = function ( title ){
- this.getApp().getFSIApp2().SetDialogTitle( title );
- }
-
- method.setSize = function ( width, height){
- var app2 = this.getApp().getFSIApp2();
- var x1 = width * app2.LogPixelsX / 96;
- var y1 = height * app2.LogPixelsY / 96;
-
- var browserDoc = this.getDoc().getRawDoc();
- var windowHnd = this.getWindowHandle();
-
- if (x1 != browserDoc.body.clientWidth || y1 != browserDoc.body.clientHeight){
- var h = windowHnd.dialogHeight;
- h = h.substr(0, h.length - 2) - 0;
- var w = windowHnd.dialogWidth;
- w = w.substr(0, w.length - 2) - 0;
-
- windowHnd.dialogWidth = w + x1 - browserDoc.body.clientWidth + 'px';
- windowHnd.dialogHeight = h + y1 - browserDoc.body.clientHeight + 'px';
- }
- }
-
- method.getPreferredWidth = function ( ){
- return this.width;
- }
-
- method.setPreferredWidth = function ( width ){
- this.width = width;
- }
-
- method.getPreferredHeight = function ( ){
- return this.height;
- }
-
- method.setPreferredHeight = function ( height ){
- this.height = height;
- }
-
- method.getWindowHandle = function (){
- return this.doc.getRawDoc().parentWindow;
- }
-
- method.release = function (){
- if (this.children && typeof this.children.length) {
- for (var i=0; i < this.children.length; i++)
- this.children[i].release();
- }
- this.parent = null;
- this.appHnd = null;
- this.children = null;
- this.listeners = null;
-
- this.doc = null;
- this.document = null;
-
- this.defaultResource = null;
- }
-
- method.super_release = method.release;
- }
- HTML.__proto__.Window = NOF_HTML_Window;
- // keep for compatibility with older versions
- //NOF.__proto__.HtmlWindow = NOF_HTML_Window;
-
- /**
- NOF.TabbedMenuWindow class. Base class for windows with a tabbed menu.
-
- Constructor
-
- @param _doc
- @param _name
- */
- function NOF_TabbedMenuWindow(_doc, _name){
- this.__proto__ = NOF_TabbedMenuWindow.prototype;
-
- if (arguments.length == 0){ //default constructor call
- this.SUPER();
- }else{
- this.SUPER( _doc, _name );
- }
- }
-
- NOF_TabbedMenuWindow.inherits (HTML.Window)
- {
- var member = NOF_TabbedMenuWindow.prototype;
- member.tabbedMenu = null;
-
- var method = NOF_TabbedMenuWindow.prototype;
- method.getMenu = function (){ return this.tabbedMenu;};
- method.setMenu = function ( menu ){ this.tabbedMenu = menu; };
-
- method.release = function (){
- this.super_release();
- this.tabbedMenu.release();
- this.tabbedMenu = null;
- }
- method.onMenuHeaderDraw = function (){
- this.document.write ( this.getMenu().getHeader() );
- }
-
- method.onMenuFooterDraw = function (){
- this.document.write ( this.getMenu().getFooter() );
- }
-
- /**
- @param event NOF.MenuEvent
- */
- method.menuSelected = function ( event ){
- var child = this.getChild( event.getSource().getId() );
- if (child != null)
- child.show(); //menu item has to be constructed w/ id = window name
- }
-
- method.menuDeselected = function ( event ){
- var child = this.getChild( event.getSource().getId() );
- if (child != null)
- child.hide(); //menu item has to be constructed w/ id = window name
- }
- }
-
- //NOF.__proto__.TabbedMenuWindow = NOF_TabbedMenuWindow;
- HTML.__proto__.TabbedMenuWindow = NOF_TabbedMenuWindow;
-
- /**
- NOF.HTML.EditorWindow class. Base class for editor windows.
-
- Constructor
-
- @param _editedElem Object
- @param _doc
- @param _name
- */
- function NOF_EditorWindow(_editedElement, _doc, _name){
- this.__proto__ = NOF_EditorWindow.prototype;
-
- if (arguments.length == 0){ //default constructor call
- this.SUPER();
- }else{
- this.SUPER( _doc, _name );
- this.editedElement = _editedElement;
- }
- }
-
- NOF_EditorWindow.inherits( HTML.Window )
- {
- var member = NOF_EditorWindow.prototype;
- member.editedElement = null;
-
- var method = NOF_EditorWindow.prototype;
- method.getEditedElement = function (){ return this.editedElement; };
- method.setEditedElement = function (editedElement){this.editedElement = editedElement; };
-
- method.release = function (){
- this.super_release();
-
- if (this.editedElement && typeof(this.editedElement.release) == 'function')
- this.editedElement.release();
- this.editedElement = null;
- }
- }
-
- HTML.__proto__.EditorWindow = NOF_EditorWindow;
-
- /**
- NOF.HTML.TabbedMenuEditorWindow class. Base class for editor windows.
-
- Constructor
-
- @param _editedElem Object
- @param _doc
- @param _name
- */
- function NOF_TabbedMenuEditorWindow(_editedElement, _doc, _name){
- this.__proto__ = NOF_TabbedMenuEditorWindow.prototype;
-
- if (arguments.length == 0){ //default constructor call
- this.SUPER();
- }else{
- this.SUPER( _doc, _name );
- this.editedElement = _editedElement;
- }
- }
-
- NOF_TabbedMenuEditorWindow.inherits( HTML.TabbedMenuWindow )
- {
- var member = NOF_TabbedMenuEditorWindow.prototype;
- member.editedElement = null;
-
- var method = NOF_TabbedMenuEditorWindow.prototype;
-
- method.parent_release = method.release;
- method.release = function (){
- this.parent_release();
- if (this.editedElement && typeof(this.editedElement.release) == 'function')
- this.editedElement.release();
- this.editedElement = null;
- }
-
- method.getEditedElement = function (){ return this.editedElement; };
- method.setEditedElement = function (editedElement){this.editedElement = editedElement; };
- }
-
- HTML.__proto__.TabbedMenuEditorWindow = NOF_TabbedMenuEditorWindow;
- }